<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>拉萨市财政局投资评审管理系统  </title>
    <link rel="stylesheet" href="css/style.css">
    <script crossorigin="anonymous" integrity="sha384-TlQc6091kl7Au04dPgLW7WK3iey+qO8dAi/LdwxaGBbszLxnizZ4xjPyNrEf+aQt" src="https://lib.baomitu.com/jquery/2.2.4/jquery.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script>
    <style>
        .ck-editor__editable_inline {
            min-height: 400px;
        }
        </style>
</head>
<body>
<!--main-header start-->

<!--main-header end-->
<!--policy-head start-->
<div class="policy-head w-1200" id="arc">
    <a class="policy-head-a" href="#" onclick="art()">政策列表</a>
    
</div>
<!--policy-head end-->
<!--policy-article start-->
<div class="policy-article w-1200" id="hello">
    <div class="policy-article-box">
        <div class="policy-article-tit">
            <input type="text" id="title" placeholder="请输入文章标题">
        </div>
        <!--policy-article-item start-->
        <!-- <div class="policy-article-item">
            <div class="label">发布时间：</div>
            <div class="policy-article-span">2021/07/10</div>
            <div class="policy-article-span">14时</div>
            <div class="policy-article-span">14时</div>
        </div> -->
        <!--policy-article-item end-->
        <div style="height: 450px;" id="editor">
           
        </div>
        
        <script src="https://cdn.ckeditor.com/ckeditor5/31.1.0/classic/ckeditor.js"></script>

        <script>

var editor;

ClassicEditor
    .create( document.querySelector( '#editor' ) )
    .then( newEditor => {
        editor = newEditor;
    } )
    .catch( error => {
        console.error( error );
    } );


        </script>
        
        <!--policy-article-add end-->
        <!--add-bottom start-->
        <div class="add-bottom mar0">
            <button class="login-btn" onclick="publish()">立即发布</button>
            <button class="login-btn bor">取消</button>
        </div>
        <!--add-bottom end-->
    </div>
</div>
<!--policy-article end-->
<script src="js/auth.js"></script>
<script>
$(document).ready(function(){
    //响应文件添加成功事件
    $("#file").change(function(){
        //创建FormData对象
        var data = new FormData();
        //为FormData对象添加数据
        $.each($('#file')[0].files, function(i, file) {
            data.append('upload_file'+i, file);
        });

       console.log(data);

        //发送数据
    $.ajax({
            url:HTTP_HOST+'api/Index/upload',
            type:'POST',
            data:data,
            cache: false,
            contentType: false, //不可缺参数
            processData: false,     //不可缺参数
            success:function(data){
                console.log(data);

           var res = ""; 

        $.each(data.result,function(k,v){
            res+= `<input type='hidden' value=`+v+` name=`+k+` class='filear'><img src="/uploadfiles/a.jpg">`;	

        });



        
           $("#content").append(res);

            },
            error:function(){
                alert('上传出错');
                $(".loading").hide();   //加载失败移除加载图片
            }
        });
    });

});

</script>

<script>


    $.get(HTTP_HOST+"api/Auth/getloginuser",function(res){
if(res.msg=='CODE_UNAUTHORIZED'){

window.location.href=HTTP_HOST+"/index.html";
}else{

loginuser = res.result;
    if(loginuser.type == "6"){
        $("#arc").append(`<a class="policy-head-a" href="#" onclick="go()">发表政策文章</a>`);
    }

}



}); 


function publish(){
    var title = $("#title").val();
    var html  = editor.getData();
    if(title == '' || html == ''){
        alert("文章标题和内容不能为空");
        return false;
    }
    $.post("/api/Ds/publish",{"title":title,"content":html},
    function(res){
            if(res.result.code == 200){

                alert("发布成功");
                window.location.reload();
            }else{
                alert(res.result.msg);
            }

    },'Json');
}

function art(){

    $("#hello").load("artlist.html");


}

function go(){

    $("#mainbox").load("publish.html");
    
    
}


    
</script>

</body>
</html>
